import json
import time
from datetime import datetime

from kafka import KafkaProducer

res = KafkaProducer(bootstrap_servers='10.90.93.29:9092')
print('生产者连接服务器成功')
i = 0
while 30 > i:
    value = {
        "id": i,
        "name": "尹军发",
        "phone": "15579757024"
    }
    b_value = json.dumps(value).encode('utf-8')
    print(f"发送数据时间===>{datetime.now()}")
    res.send(topic='new', value=b_value)
    i += 1
    time.sleep(1)
res.close()
